var _util = require("util/util.js");

var user = {
	//登录
	login : function(userinfo , resolve,reject){
		_util.request({
            url     : _util.getServerUrl('/user/login.do'),
            method  : 'post',
            data 	: userinfo,
            success : resolve,
            error   : reject
        });
	}, 
    //获得用户信息
    get_user_info : function(resolve,reject){
        _util.request({
            url     : _util.getServerUrl('/user/get_user_info.do'),
            method  : 'post',
            success : resolve,
            error   : reject
        });
    },
    //查询收藏书籍数量
    query_article_count : function(resolve,reject){
        _util.request({
            url     : _util.getServerUrl('/user/query_article_count.do'),
            method  : 'post',
            success : resolve,
            error   : reject
        });
    },
    //获取当前用户信息
    get_information : function(resolve,reject){
        _util.request({
            url     : _util.getServerUrl('/user/get_information.do'),
            method  : 'post',
            success : resolve,
            error   : reject
        });
    },
    //登录
    logout : function(){
        _util.request({
            url     : _util.getServerUrl('/user/logout.do'),
            method  : 'post',
        });
    },
    //检查用户名或邮箱是否重复
    check_valid : function(data,resolve,reject){
        _util.request({
            url     : _util.getServerUrl('/user/check_valid.do'),
            method  : 'post',
            data    : data,
            success : resolve,
            error   : reject
        });
    },
    //检查用户名或邮箱是否重复
    register : function(data,resolve,reject){
        _util.request({
            url     : _util.getServerUrl('/user/register.do'),
            method  : 'post',
            data    : data,
            success : resolve,
            error   : reject
        });
    },
    //更新用户信息
    updateInformation : function(data,resolve,reject){
        _util.request({
            url     : _util.getServerUrl('/user/update_information.do'),
            method  : 'post',
            data    : data,
            success : resolve,
            error   : reject
        });
    },
    //登录状态下重置密码
    restPassword : function(data,resolve,reject){
        _util.request({
            url     : _util.getServerUrl('/user/rest_password.do'),
            method  : 'post',
            data    : data,
            success : resolve,
            error   : reject
        });
    },
    //收藏文章
    addArticle : function(data,resolve,reject){
        _util.request({
            url     : _util.getServerUrl('/user/add_article.do'),
            method  : 'post',
            data    : data,
            success : resolve,
            error   : reject
        });
    },
    //取消收藏文章
    removeArticle : function(data,resolve,reject){
        _util.request({
            url     : _util.getServerUrl('/user/remove_article.do'),
            method  : 'post',
            data    : data,
            success : resolve,
            error   : reject
        });
    }
}

module.exports = user;